// 
// SoapTrace.Net - A soap message monitoring utility. 
// 
// Copyright (C) 2004-2009 Matthew Ward
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, orViewMenuItemSeparator1
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// Matthew Ward (mrward@users.sourceforge.net)
// 

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Reflection;

namespace SoapTrace
{
	/// <summary>
	/// Main error message form for the soap trace application.
	/// </summary>
	public partial class ErrorReportingForm : System.Windows.Forms.Form
	{
		private ErrorReportUserControl.ExpandEventHandler 
			m_ExpandEventHandler;

		private int UnexpandedHeight;
		
		private int UnexpandedControlHeight;

		/// <summary>
		/// Creates a new instance of the <see cref="ErrorReportingForm"/>
		/// </summary>
		public ErrorReportingForm( )
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent( );

			m_ExpandEventHandler = new ErrorReportUserControl.ExpandEventHandler( OnExpand );
			ErrorReport.Expand += m_ExpandEventHandler;

			UnexpandedHeight = this.Height;
			UnexpandedControlHeight = ErrorReport.Height;
		}

		/// <summary>
		/// Gets or sets the error message.
		/// </summary>
		public string ErrorMessage
		{
			get
			{
				return ErrorReport.ErrorMessage;
			}

			set
			{
				ErrorReport.ErrorMessage = value;
			}
		}

		/// <summary>
		/// Gets or sets the detailed error message.
		/// </summary>
		public string ErrorDetails
		{
			get
			{
				return ErrorReport.ErrorDetails;
			}

			set
			{
				ErrorReport.ErrorDetails = value;
			}
		}

		/// <summary>
		/// Display the error information.
		/// </summary>
		/// <param name="message">The error message.</param>
		/// <param name="e">The exception.</param>
		public DialogResult ShowDialog( string message, Exception e )
		{
			ErrorReport.SetErrorText( message, e );

			return base.ShowDialog( );
		}
		
		/// <summary>
		/// Removes the expand handler when the form is closing.
		/// </summary>
		/// <param name="e"></param>
		protected override void OnClosing( CancelEventArgs e )
		{
			ErrorReport.Expand -= m_ExpandEventHandler;

			base.OnClosing( e );
		}
		
		private void OnExpand( object sender, ExpandEventArgs e )
		{
			if( e.Expand )
			{
				Height = UnexpandedHeight + ( ErrorReport.Height - UnexpandedControlHeight );	
			}
			else
			{
				Height = UnexpandedHeight;
			}
		}		
	}
}
